home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / fadapt.c < prev    next >
Text File  |  1994-01-03  |  25KB  |  780 lines

  1. /*************************************************************************
  2. *                                                                        *
  3. *  Name : fadapt.c                                                       *
  4. *                                                                        *
  5. *  Purpose : Driver program of the ADAPTOR translation tool              *
  6. *                                                                        *
  7. *  Author : Dr. Thomas Brandes, GMD, I1.HR                               *
  8. *                                                                        *
  9. *  Last Update : June 1993                                               *
  10. *                                                                        *
  11. *************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "global.h"
  16. #include "Parser.h"
  17. #include "Tree.h"
  18. #include "MakeDefs.h"
  19. #include "Analysi.h"
  20. #include "Temporar.h"
  21. #include "Init.h"
  22. #include "Serial.h"
  23. #include "Transfor.h"
  24. #include "Definiti.h"
  25. #include "Unparse.h"
  26. #include "CallGraF.h"     /* for TheCallGraph */
  27. #include "Calling.h"
  28. #include "DataFlow.h"
  29.  
  30. # ifdef alliant
  31. # include <fcntl.h>        /* for testing fileaccess */
  32. # else
  33. # include <unistd.h>        /* for testing fileaccess */
  34. # endif
  35.  
  36. #include <sys/types.h>        /* for getpid */
  37.  
  38. /* external variables defined in this module */
  39.  
  40. int interactive = 0;
  41. char ** fad_argv;     /* used for makefile writer */
  42. int     fad_argc;     /* used for makefile writer */
  43.  
  44. #define DEBUG(x)
  45. #define MAXCOMMANDLINELENGTH 1024
  46. #define MAXPATHNAMELENGTH 1024
  47. #define USETMP 2
  48. #define TMP "/tmp/adaptor"
  49.  
  50. static int usetmp;
  51. static char cat[MAXCOMMANDLINELENGTH];
  52. static char tempfile[MAXCOMMANDLINELENGTH];
  53.  
  54. /****************************************************************/
  55. /* is_source_file()                        */
  56. /* INPUT:    string                        */
  57. /*        length (length of string)            */
  58. /* OUTPUT:    true, if string is an allowed fortran filename    */
  59. /*        false, if string isn`t a fortran filename    */
  60. /****************************************************************/
  61.  
  62. bool is_source_file (string, length)
  63. char *string;
  64. int length;
  65. {
  66.    if (strcmp(string+length-2,".f") == 0) return (true);
  67.    if (strcmp(string+length-2,".F") == 0) return (true);
  68.    if (strcmp(string+length-3,".f9") == 0) return (true);
  69.    if (strcmp(string+length-3,".F9") == 0) return (true);
  70.    if (strcmp(string+length-4,".fcm") == 0) return (true);
  71.    return(false);
  72. }
  73.  
  74.  
  75. int SourceParser (fname)
  76. char *fname;
  77.  
  78. /* parses the fortran file 'fname', returns number
  79.    of syntax errors in the source file
  80.    -1 : file could not be opened                       */
  81.  
  82. {  int Errors;
  83.  
  84.    filename = fname;    /* for makefile write, will know the file name */
  85.    BeginFile (fname);
  86.    BeginPos (fname);
  87.    Errors = Parse ();
  88.    ClosePos ();
  89.    if (Errors == 0)
  90.        sprintf (last_message, "Succesful parsed");
  91.      else
  92.        sprintf (last_message, "Parsing with %d Errors", Errors);
  93.    return (Errors);
  94. }
  95.  
  96. int SourceCheck ()
  97. {  if (!CheckTree (TreeRoot))
  98.      { sprintf (last_message, "Tree is not okay");
  99.        return 1;
  100.      }
  101.     else
  102.      { sprintf (last_message, "Tree is good");
  103.        return 0;
  104.      }
  105. }
  106.  
  107. int SourceSemantic ()
  108.  
  109. { int phase;
  110.   int errors;
  111.  
  112.   printf ("\n");
  113.   printf ("SEMANTIC PHASE 1 : Make Definitions\n");
  114.   phase = 1;
  115.   MakeDefs (TreeRoot);
  116.   errors = protocol_errors ();
  117.   if (errors > 0)
  118.     { printf (" %d Errors occured, see adaptor.def\n", errors);
  119.       sprintf (last_message,
  120.          "%d Errors in SEMANTIC 1 : MakeDefs (see adaptor.def)", errors);
  121.          goto Ende;
  122.     }
  123.   printf (" successfully completed\n");
  124.  
  125.   printf ("\n");
  126.   printf ("SEMANTIC PHASE 2 : Checking\n");
  127.   phase = 2;
  128.   BeginSemantic ();
  129.   Semantic (TreeRoot);
  130.   CloseSemantic ();
  131.   errors = protocol_errors ();
  132.   if (errors > 0)
  133.     { printf (" %d Errors occured, see adaptor.sem\n", errors);
  134.       sprintf (last_message,
  135.          "%d Errors in SEMANTIC 2 : Checks (see adaptor.sem)", errors);
  136.       goto Ende;
  137.     }
  138.   printf (" successfully completed\n");
  139.  
  140.   printf ("\n");
  141.   printf ("SEMANTIC PHASE 3 : Control Flow\n");
  142.   phase = 3;
  143.   ControlFlow (TreeRoot);
  144.   errors = protocol_errors ();
  145.   if (errors > 0)
  146.     { printf (" %d Errors occured, see adaptor.cf\n", errors);
  147.       sprintf (last_message,
  148.          "%d Errors in SEMANTIC 3 : Control Flow (see adaptor.cf)", errors);
  149.       goto Ende;
  150.     }
  151.   printf (" successfully completed\n");
  152.  
  153.   sprintf (last_message, "Semantic Analysis was successful");
  154.   phase = 0;
  155.  
  156. Ende: return (phase);
  157. }
  158.  
  159. int SourceWrite ()
  160.  
  161. {  FILE *myFile;
  162.    printf ("Write Tree on File test.out \n");
  163.    myFile = fopen ("test.out","w");
  164.    if (myFile == (FILE *) NULL)
  165.     { printf ("Adaptor failed to open file test.out\n");
  166.       printf ("Please check permissions\n");
  167.       exit (-1);
  168.     }
  169.    WriteTree (myFile, TreeRoot);
  170.    fclose (myFile);
  171.    printf ("Writing Tree is ready\n");
  172.    sprintf (last_message, "Abtract Tree written to file test.out");
  173. }
  174.  
  175. int SourceCalling ()
  176.  
  177. {  FILE *myFile;
  178.  
  179.    BeginCalling ();
  180.    printf ("Starting Calling Analysis \n");
  181.    Calling (TreeRoot);
  182.    printf ("Ending Calling Analysis\n");
  183.  
  184.    /* printf ("Write CallGraph on File test.cg \n");
  185.       myFile = fopen ("test.cg","w");
  186.       if (myFile == (FILE *) NULL)
  187.        { printf ("Adaptor failed to open file test.cg\n");
  188.          printf ("Please check permissions\n");
  189.          exit (-1);
  190.        }
  191.       WriteCallGraph (myFile, TheCallGraph);
  192.       fclose (myFile);
  193.       printf ("Writing CallGraph is ready\n");
  194.       CloseCalling ();
  195.    */
  196.  
  197.    /* import CGFile from Calling.h */
  198.    printf ("Start Writing CallGraph \n");
  199.    CGFile = fopen ("test.cal","w");
  200.    if (CGFile == (FILE *) NULL)
  201.     { printf ("Adaptor failed to open file test.cal\n");
  202.       printf ("Please check permissions\n");
  203.       exit (-1);
  204.     }
  205.    OutCallGraph (TheCallGraph);
  206.    fclose (CGFile);
  207.    printf ("End Writing CallGraph to a File\n");
  208.    sprintf (last_message, "Call Graph has been generated");
  209. }
  210.  
  211. int SourceDataFlow ()
  212.  
  213. {  BeginDataFlow ();
  214.    printf ("Starting Data Flow Analysis \n");
  215.    DataFlow (TreeRoot);
  216.    printf ("Ending Data Flow Analysis\n");
  217.    CloseDataFlow ();
  218.  
  219.    printf ("Start Writing Dependences \n");
  220.    DepFile = fopen ("test.dp","w");
  221.    if (DepFile == (FILE *) NULL)
  222.     { printf ("Adaptor failed to open file test.dp\n");
  223.       printf ("Please check permissions\n");
  224.       exit (-1);
  225.     }
  226.    OutDependences (TreeRoot);
  227.    fclose (DepFile);
  228.    printf ("End Writing Dependences to a File\n");
  229. }
  230.  
  231. void SourceUnparse ()
  232.  
  233. { BeginUnparse ();
  234.   Unparse (TreeRoot);
  235.   CloseUnparse ();
  236. }
  237.  
  238. int SourceAdapt ()
  239. {  FILE *f;
  240.    tTree HostRoot;
  241.    int errors;
  242.    int phase;
  243.    char node_file [10];  /* name of file for node/cube/node1 program */
  244.  
  245.    /* PHASE 1 : ADAPTOR Analysis */
  246.  
  247.      printf ("\n");
  248.      printf ("ADAPTOR PHASE 1 : Analysis\n");
  249.      phase = 1;
  250.      BeginAdaptAnalysis ();
  251.      AdaptAnalysis (TreeRoot);
  252.      CloseAdaptAnalysis ();
  253.      errors = protocol_errors ();
  254.      if (errors > 0)
  255.        { printf (" %d Errors occured, see adaptor.anl\n", errors);
  256.          sprintf (last_message,
  257.             "%d Errors in PHASE 1 : Analysis (see adaptor.anl)", errors);
  258.          goto Ende;
  259.        }
  260.      printf (" successfully completed\n");
  261.  
  262.    /* PHASE 2 : ADAPTOR Distributions */
  263.  
  264.      printf ("\n");
  265.      printf ("ADAPTOR PHASE 2 : Distributions\n");
  266.      phase = 2;
  267.      BeginAdaptDistributions ();
  268.      AdaptDistributions (TreeRoot);
  269.      CloseAdaptDistributions ();
  270.      errors = protocol_errors ();
  271.      if (errors > 0)
  272.        { printf (" %d Errors occured, see adaptor.dis\n", errors);
  273.          sprintf (last_message,
  274.             "%d Errors in PHASE 2 : Distributions (see adaptor.dis)", errors);
  275.          goto Ende;
  276.        }
  277.      printf (" successfully completed\n");
  278.  
  279.    /* PHASE 3 : ADAPTOR Temporary */
  280.  
  281.      printf ("\n");
  282.      printf ("ADAPTOR PHASE 3 : Temporary Variables \n");
  283.      phase = 3;
  284.      AdaptTemporary (TreeRoot);
  285.      errors = protocol_errors ();
  286.      if (errors > 0)
  287.        { printf (" %d Errors occured, see adaptor.tmp\n", errors);
  288.          sprintf (last_message,
  289.             "%d Errors in PHASE 3 : Temporary (see adaptor.tmp)", errors);
  290.          goto Ende;
  291.        }
  292.      if (!CheckTree (TreeRoot))
  293.        { printf ("Tree is not okay after creating temporaries \n");
  294.          sprintf (last_message, "Illegal Tree after PHASE 3 : Temporary ");
  295.          goto Ende;
  296.        }
  297.      printf (" successfully completed\n");
  298.  
  299.    /* PHASE 4 : ADAPTOR Initialization */
  300.  
  301.      printf ("\n");
  302.      printf ("ADAPTOR PHASE 4 : Initial\n");
  303.      phase = 4;
  304.      AdaptInit (TreeRoot);
  305.      errors = protocol_errors ();
  306.      if (errors > 0)
  307.        { printf (" %d Errors occured, see adaptor.ini\n", errors);
  308.          sprintf (last_message,
  309.             "%d Errors in PHASE 4 : Initial (see adaptor.ini)", errors);
  310.          phase = 4;
  311.          goto Ende;
  312.        }
  313.      if (!CheckTree (TreeRoot))
  314.        { printf ("Tree is not okay after initial transformation\n");
  315.          sprintf (last_message, "Illegal Tree after PHASE 3 : Initial ");
  316.          goto Ende;
  317.        }
  318.      printf (" successfully completed\n");
  319.  
  320.    /* PHASE 5 : ADAPTOR Serialization */
  321.  
  322.      printf ("\n");
  323.      printf ("ADAPTOR PHASE 5 : Serial\n");
  324.      phase = 5;
  325.      AdaptSerial (TreeRoot);
  326.      errors = protocol_errors ();
  327.      if (errors > 0)
  328.        { printf (" %d Errors occured, see adaptor.seq\n", errors);
  329.          sprintf (last_message,
  330.             "%d Errors in PHASE 5 : Serial (see adaptor.seq)", errors);
  331.          phase = 5;
  332.          goto Ende;
  333.        }
  334.      if (!CheckTree (TreeRoot))
  335.        { printf ("Tree is not okay after serialization\n");
  336.          sprintf (last_message, "Illegal Tree after PHASE 5 : Serial ");
  337.          goto Ende;
  338.        }
  339.      SourceUnparse ();
  340.      printf (" successfully completed (see unparse.f)\n");
  341.  
  342.    /* PHASE 6 : ADAPTOR Transformation */
  343.  
  344.      printf ("\n");
  345.      printf ("ADAPTOR PHASE 6 : Transform\n");
  346.      phase = 6;
  347.  
  348.      if (target_model == HOST_NODE)
  349.      { HostRoot = CopyTree (TreeRoot);
  350.        HostAdapt (HostRoot);
  351.        errors = protocol_errors ();
  352.        if (errors > 0)
  353.          { printf (" %d Errors occured, see adaptor.tra\n", errors);
  354.            sprintf (last_message,
  355.               "%d Errors in PHASE 5 : Host (see adaptor.tra)", errors);
  356.            goto Ende;
  357.          }
  358.        if (!CheckTree (HostRoot))
  359.          { printf ("Host Tree is not okay\n");
  360.            sprintf (last_message,"Illegal Host Tree after PHASE 5 : Transform");
  361.            goto Ende;
  362.          }
  363.  
  364.        f = fopen ("host.f", "w");
  365.        if (f == (FILE *) NULL)
  366.         { printf ("Adaptor failed to open file host.f\n");
  367.           printf ("Please check permissions\n");
  368.           exit (-1);
  369.         }
  370.        FileUnparse (f, HostRoot);
  371.        fclose (f);
  372.        printf (" Host program successfully generated\n");
  373.      }
  374.  
  375.      /* define node_file */
  376.  
  377.      if (target_model == HOST_NODE)
  378.         sprintf (node_file, "node.f");
  379.       else if (target_model == UNI_PROC)
  380.         sprintf (node_file, "node1.f");
  381.       else /* target_model == ONLY_NODE */
  382.         sprintf (node_file, "cube.f");
  383.  
  384.      NodeAdapt (TreeRoot);
  385.      errors = protocol_errors ();
  386.      if (errors > 0)
  387.        { printf (" %d Errors occured, see adaptor.tra\n", errors);
  388.          sprintf (last_message,
  389.             "%d Errors in PHASE 6 : Node (see adaptor.tra)", errors);
  390.          goto Ende;
  391.        }
  392.      if (!CheckTree (TreeRoot))
  393.        { printf ("Node Tree is not okay\n");
  394.          sprintf (last_message, "Illegal Node Tree after PHASE 5 : Transform");
  395.          goto Ende;
  396.        }
  397.  
  398.      f = fopen (node_file, "w");
  399.      if (f == (FILE *) NULL)
  400.       { printf ("Adaptor failed to open file %s\n", node_file);
  401.         printf ("Please check permissions\n");
  402.         exit (-1);
  403.       }
  404.      FileUnparse (f, TreeRoot);
  405.      fclose (f);
  406.      printf (" Node program (%s) successfully generated\n", node_file);
  407.  
  408.      sprintf (last_message, "Translation successful");
  409.      phase = 0;
  410.  
  411. Ende: return(phase);
  412. }
  413.  
  414. int command;       /* global used */
  415. char *filename;
  416.  
  417. /****************************************************************
  418. *                                                               *
  419. * check_options:                        *
  420. *                                                               *
  421. * INPUT:    none                        *
  422. * OUTPUT:    TRUE, if options are ok                *
  423. *        FALSE, if options are not allowed        *
  424. *                                                               *
  425. ****************************************************************/
  426.  
  427. bool check_options()
  428.  
  429. { char filename [MAXPATHNAMELENGTH];
  430.  
  431.   /* Test 1 : interactive use requires some files */
  432.  
  433.   if (command == 0)
  434.     {  if (access (PHOME, R_OK) != 0)
  435.          { fprintf(stderr,"No access on ADAPTOR Home-Directory %s\n", PHOME);
  436.            return (false);
  437.          }
  438.  
  439.        sprintf (filename, "%s/welcome", PHOME);
  440.        if (access (filename,R_OK) != 0)
  441.           { fprintf(stderr,"no access on welcome file %s\n", filename);
  442.             return(false);
  443.           }
  444.  
  445.        sprintf (filename, "%s/help", PHOME);
  446.        if (access (filename,R_OK) != 0)
  447.           { fprintf(stderr,"no access on help file %s\n", filename);
  448.             return(false);
  449.           }
  450.     }
  451.  
  452.   /* Test 2 : do nout use FORTRAN_90 together with STATIC_ARRAYS */
  453.  
  454.   if ((target_language == FORTRAN_90) && (array_kind == STATIC_ARRAYS))
  455.  
  456.     { sprintf (last_message,
  457.                "FORTRAN 90 and STATIC ARRAYS cannot be used together");
  458.       fprintf(stderr, "%s\n", last_message);
  459.       return(false);
  460.     }
  461.   if (MinProc < 1)
  462.     { sprintf (last_message, "At least one processor is required");
  463.       fprintf(stderr, "%s\n", last_message);
  464.       return(false);
  465.     }
  466.   if (StaticArraySize < 1)
  467.     { sprintf (last_message, "Static array size < 1 does not make sense");
  468.       fprintf(stderr, "%s\n", last_message);
  469.       return(false);
  470.     }
  471.   return(true);
  472. }
  473.  
  474. eval_arg (argc, argv)
  475. int argc;
  476. char **argv;
  477. { int i;
  478.   char *comm;
  479.   void print_help ();
  480.   void print_defaults ();
  481.  
  482.   command = 0;
  483.  
  484.   target_machine  = predefined_target_machine;
  485.   target_language = predefined_target_language;
  486.   target_model    = predefined_target_model;
  487.   array_kind      = predefined_array_kind;
  488.   ddefault_kind   = predefined_ddefault_kind;
  489.   MinProc         = predefined_MinProc;
  490.   StaticArraySize = predefined_StaticArraySize;
  491.   split_flag      = predefined_split_flag;
  492.  
  493.   strcpy (PHOME, predefined_PHOME);
  494.  
  495.   /* PHOME can be replaced with value of environment variable */
  496.  
  497.   if (getenv(PHOME_envvar))
  498.       strcpy(PHOME,getenv(PHOME_envvar));
  499.  
  500.   fad_argv = argv;
  501.   fad_argc = argc;
  502.  
  503.   usetmp = 0;
  504.   sprintf(tempfile,"%s%d",TMP,getpid());
  505.   sprintf(cat,"cat >%s",tempfile);
  506.   i=1;
  507.   while (i<argc)
  508.     { comm = argv[i];
  509. /* -adapt is default when using filenames as argument*/
  510.         if ('-' != comm[0])
  511.         {
  512.                 comm = "-adapt";
  513.                 usetmp++;
  514.                 if (usetmp<USETMP) filename = argv[i];
  515.                 else filename = tempfile;
  516.                 if (access(argv[i],R_OK) != 0)
  517.                 {
  518.                         fprintf(stderr,"No access on %s!\n",argv[i]);
  519.             exit(-1);
  520.         }
  521.         else
  522.         {
  523.             if (is_source_file(argv[i],strlen(argv[i])) == false)
  524.             {
  525.                 fprintf(stderr,"No Fortran filename\n");
  526.                 exit(-1);
  527.             }
  528.             strcpy(cat+strlen(cat)-strlen(tempfile)-1,argv[i]);
  529.             strcpy(cat+strlen(cat)," >");
  530.             strcpy(cat+strlen(cat),tempfile);
  531.         }
  532.     }
  533. /* end of -adapt is default when using filenames as argument */
  534.       if (strcmp(comm,"-parse") == 0)
  535.          { command = 1;
  536.      }
  537.       else if (strcmp(comm,"-semantic") == 0)
  538.          { command = 2;
  539.      }
  540.       else if (strcmp(comm,"-call") == 0)
  541.          { command = 3;
  542.      }
  543.       else if (strcmp(comm,"-adapt") == 0)
  544.          { command = 4;
  545.      }
  546.       else if (strcmp(comm,"-p") == 0)
  547.          {
  548.              if ((argc >= (i+1)) && (sscanf (argv[i+1], "%d", &MinProc)))
  549.                  i++;
  550.          else
  551.          {
  552.         fprintf(stderr,"argument missing or argument type wrong\n");
  553.         fprintf(stderr,"needed for argument -p\n");
  554.         exit(-1);
  555.          }
  556.          }
  557.       else if (strcmp(comm,"-F90") == 0)
  558.            target_language = FORTRAN_90;
  559.       else if (strcmp(comm,"-F77") == 0)
  560.            target_language = FORTRAN_77;
  561.       else if (strcmp(comm,"-S") == 0)
  562.            { array_kind = STATIC_ARRAYS;
  563.              if ((argc > (i+1)) &&
  564.         (sscanf (argv[i+1], "%d", &StaticArraySize)))
  565.                  i++;
  566.          else
  567.          {
  568.         fprintf(stderr,"argument missing or argument type wrong\n");
  569.         fprintf(stderr,"needed for argument -S\n");
  570.         exit(-1);
  571.          }
  572.            }
  573.       else if (strcmp(comm,"-D") == 0)
  574.            array_kind = DYNAMIC_ARRAYS;
  575.       else if (strcmp(comm,"-sun") == 0)
  576.            target_machine = SUN4_PVM;
  577.       else if (strcmp(comm,"-os2pvm") == 0)
  578.            target_machine = OS2_PVM;
  579.       else if (strcmp(comm,"-ibm") == 0)
  580.            target_machine = RIOS_PVM;
  581.       else if (strcmp(comm,"-alliant") == 0)
  582.            target_machine = ALLIANT;
  583.       else if (strcmp(comm,"-all_pvm") == 0)
  584.            target_machine = ALL_PVM;
  585.       else if (strcmp(comm,"-ipsc") == 0)
  586.            target_machine = IPSC_860;
  587.       else if (strcmp(comm,"-gc") == 0)
  588.            target_machine = PARSYTEC_GC;
  589.       else if (strcmp(comm,"-meiko_cs1") == 0)
  590.            target_machine = MEIKO_CS1;
  591.       else if (strcmp(comm,"-meiko_cs2") == 0)
  592.            target_machine = MEIKO_CS2;
  593.       else if (strcmp(comm,"-ksr1") == 0)
  594.            target_machine = KSR1;
  595.       else if (strcmp(comm,"-ksr") == 0)
  596.            target_machine = KSR1;
  597.       else if (strcmp(comm,"-ksr1_pvm") == 0)
  598.            target_machine = KSR1_PVM;
  599.       else if (strcmp(comm,"-ksr_pvm") == 0)
  600.            target_machine = KSR1_PVM;
  601.       else if (strcmp(comm,"-cm5") == 0)
  602.            target_machine = CM5;
  603.       else if (strcmp(comm,"-cm") == 0)
  604.            target_machine = CM5;
  605.       else if (strcmp(comm,"-sgi") == 0)
  606.            target_machine = SGI;
  607.       else if (strcmp(comm,"-1") == 0)
  608.            target_model = UNI_PROC;
  609.       else if (strcmp(comm,"-uniproc") == 0)
  610.            target_model = UNI_PROC;
  611.       else if (strcmp(comm,"-split") == 0)
  612.            split_flag = 1;
  613.       else if (strcmp(comm,"-nosplit") == 0)
  614.            split_flag = 0;
  615.       else if (strcmp(comm,"-ddr") == 0)
  616.            ddefault_kind = DDEFAULT_REPLICATED;
  617.       else if (strcmp(comm,"-ddb") == 0)
  618.            ddefault_kind = DDEFAULT_DISTRIBUTED;
  619.       else if (strcmp(comm,"-ddcm") == 0)
  620.            ddefault_kind = DDEFAULT_CM;
  621.       else if (strcmp(comm,"-N") == 0)
  622.            target_model = ONLY_NODE;
  623.       else if (strcmp(comm,"-H") == 0)
  624.            target_model = HOST_NODE;
  625.       else if (strcmp(comm,"-home") == 0)
  626.          {
  627.              if ((argc > (i+1)) && (sscanf (argv[i+1], "%s", PHOME)))
  628.                  i++;
  629.          else
  630.          {
  631.         fprintf(stderr,"argument missing or argument type wrong\n");
  632.         fprintf(stderr,"needed for argument -home\n");
  633.         exit(-1);
  634.          }
  635.          }
  636.       else if (strcmp(comm,"-help") == 0)
  637.            { print_help ();
  638.              exit (0);
  639.            }
  640.       else if (strcmp(comm,"-defaults") == 0)
  641.            { print_defaults ();
  642.              exit (0);
  643.            }
  644.       else
  645.      { printf ("  fadapt -help\n");
  646.        printf ("  fadapt -defaults\n");
  647.        exit (-1);
  648.      }
  649.       i++;
  650.     }
  651.     if (!check_options())
  652.     {
  653.         exit(-1);
  654.     }
  655.     if (usetmp>=USETMP) system(cat);
  656. }
  657.  
  658. void print_help ()
  659. {
  660.  printf ("\n");
  661.  printf ("fadapt\n");
  662.  printf ("  [-home <dir> ]     Home Directory\n");
  663.  printf ("  [-sun]             target machine = SUN4, PVM\n");
  664.  printf ("  [-sgipvm]          target machine = SGI,  PVM\n");
  665.  printf ("  [-ibm]             target machine = IBM, PVM\n");
  666.  printf ("  [-alliant]         target machine = Alliant FX/2800\n");
  667.  printf ("  [-all_pvm]         target machine = Alliant FX/2800 with PVM\n");
  668.  printf ("  [-ipsc]            target machine = iPSC/860\n");
  669.  printf ("  [-gc]              target machine = Parsytec GC\n");
  670.  printf ("  [-meiko_cs1]       target machine = Meiko CS 1\n");
  671.  printf ("  [-meiko_cs2]       target machine = Meiko CS 2\n");
  672.  printf ("  [-ksr]             target machine = KSR 1\n");
  673.  printf ("  [-ksr_pvm]         target machine = KSR 1 with PVM\n");
  674.  printf ("  [-sgi]             target machine = Silicon Graphics (IRIX)\n");
  675.  printf ("  [-cm]              target machine = CM 5\n");
  676.  printf ("  \n");
  677.  printf ("  [-H | -N | -1]     model = HOST_NODE, ONLY_NODE, UNI_PROC\n");
  678.  printf ("  [-uniproc]         model = UNI_PROC, same as -1\n");
  679.  printf ("  [-p <n>]           Minimal number of processes\n");
  680.  printf ("  [-F90|-F77]        Target Language (Fortran 77 or Fortran 90\n");
  681.  printf ("  [-S size|-D]       Distributed/Dynamic arrays static or dynamic\n");
  682.  printf ("  [-split|-nosplit]  Split up generated sources\n");
  683.  printf ("  [-ddr|-ddb|-ddcm]  Default Distribution replicated/block/CM\n");
  684.  printf ("\n");
  685.  printf ("  ( -parse | -semantic | -call | -adapt ) filename\n");
  686.  printf ("\n");
  687. } /* print_help */
  688.  
  689. void print_defaults ()
  690. { printf ("\n");
  691.   printf ("Defaults of fadapt:\n");
  692.   printf ("===================\n");
  693.   printf ("\n");
  694.   printf ("Home Directory       : %s\n", PHOME);
  695.   printf ("Default Distribution : ");
  696.   if (ddefault_kind == DDEFAULT_REPLICATED) printf ("replicated (ddr)\n");
  697.   if (ddefault_kind == DDEFAULT_DISTRIBUTED)
  698.       printf ("arrays are block distributed (ddb)\n");
  699.   if (ddefault_kind == DDEFAULT_CM) printf ("like CM (ddcm)\n");
  700.   printf ("Target Machine       : ");
  701.   if (target_machine == ALLIANT)     printf ("alliant (Alliant FX/2800)");
  702.   if (target_machine == ALL_PVM)     printf ("all_pvm (Alliant FX/2800, PVM)");
  703.   if (target_machine == SUN4_PVM)    printf ("sun (SUN4, PVM)");
  704.   if (target_machine == OS2_PVM)     printf ("os2pvm (OS2, PVM)");
  705.   if (target_machine == RIOS_PVM)    printf ("ibm (IBM RISC, PVM)");
  706.   if (target_machine == IPSC_860)    printf ("ipsc (iPSC/860)");
  707.   if (target_machine == PARSYTEC_GC) printf ("gc (Parsytec GCel)");
  708.   if (target_machine == MEIKO_CS1)   printf ("meiko_cs1 (Meiko CS1)");
  709.   if (target_machine == MEIKO_CS2)   printf ("meiko_cs2 (Meiko CS2)");
  710.   if (target_machine == CM5)         printf ("Connection Machine 5");
  711.   if (target_machine == KSR1)        printf ("Kendall Square Research 1");
  712.   if (target_machine == SGI)         printf ("sgi (Silicon Graphics)");
  713.   printf ("\n");
  714.   printf ("Target Model         : ");
  715.   if (target_model == UNI_PROC)   printf("One Processor");
  716.   if (target_model == ONLY_NODE)  printf("N=Only Nodes");
  717.   if (target_model == HOST_NODE)  printf("H=Host+Nodes");
  718.   printf ("\n");
  719.   printf ("Target Language      : ");
  720.   if (target_language == FORTRAN_77)  printf("F77 (Fortran 77)");
  721.   if (target_language == FORTRAN_90)  printf("F90 (Fortran 90)");
  722.   printf ("\n\n");
  723.   printf ("Distributed/Dynamic Arrays will be : ");
  724.   if (array_kind == STATIC_ARRAYS)
  725.      printf("S=static with minimal size = %d", StaticArraySize);
  726.   if (array_kind == DYNAMIC_ARRAYS) printf("D=dynamic");
  727.   printf ("\n");
  728.   printf ("Minimal number of processes (p)    : %d\n", MinProc);
  729.   printf ("\n");
  730.   if (split_flag)
  731.      printf ("Generated sources will be split (split)\n");
  732.    else
  733.      printf ("Generated sources will not be split (nosplit)\n");
  734.   printf ("\n");
  735. } /* print_defaults */
  736.  
  737. main(argc, argv)
  738. int argc;
  739. char **argv;
  740.  
  741. {  int ErrorCount;
  742.  
  743.    eval_arg (argc, argv);
  744.  
  745.    if (command == 0)
  746. #ifdef BATCH
  747.        { printf ("Only Batch version\n");
  748.          exit(-1);
  749.        }
  750. #else
  751.        { interactive = 1;
  752.          xmenu (argc, argv);   /* widget management */
  753.        }
  754. #endif
  755.      else
  756.    { printf ("Command = %d, FileName : %s\n", command, filename);
  757.      ErrorCount = SourceParser (filename);
  758.      printf ("%s\n", last_message);
  759.      if (ErrorCount > 0)
  760.        exit (-1);
  761.      if (command > 1)
  762.         { ErrorCount = SourceSemantic ();
  763.           printf ("%s\n", last_message);
  764.           if (ErrorCount > 0) exit (-1);
  765.         }
  766.      /* SourceWrite (); */
  767.      if (command == 3) SourceCalling ();
  768.      /* SourceCheck (); */
  769.      if (command == 4) SourceAdapt ();
  770.    }
  771.    if (usetmp>=USETMP)
  772.    {
  773.     char remove[MAXCOMMANDLINELENGTH];
  774.     sprintf(remove,"rm -f %s",tempfile);
  775.     system(remove);
  776.    }
  777.    exit (0);
  778. }
  779.  
  780.